# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dim import jms_dim__dim_lmdm_sys_first_code, jms_dim__dim_sys_network_detail_dt
from jms.ods import jms_ods__tab_barscan_warehousing, jms_ods__tab_barscan_taking, jms_ods__tab_barscan_centerarrival, jms_ods__tab_barscan_arrival, jms_ods__tab_reback_transfer_express
from jms.ods.oms import jms_ods__yl_oms_oms_waybill, jms_ods__yl_oms_interceptorpiece__0730
from jms.ods.tab import jms_ods__tab_barscan_centersend__0730, jms_ods__tab_barscan_loading__0730, jms_ods__tab_barscan_unloading__0730, jms_ods__tab_barscan_difficult__0730, \
    jms_ods__tab_barscan_collect__0730, jms_ods__tab_barscan_sign__0730, jms_ods__tab_aviation_send_record__0730, jms_ods__tab_send_goods_report__0730
from jms.ods.tms import jms_ods__yl_tmsnew_branch_shipment_stop__0730, \
    jms_ods__yl_tmsnew_tms_shipment_stop__0730, jms_ods__yl_tmsnew_branch_shipment__0730, jms_ods__yl_tmsnew_tms_shipment__0730
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dm__dm_cn_export_departure_store_dt = SparkSqlOperator(
    task_id='jms_dm__dm_cn_export_departure_store_dt',
    email=['shenjiaming@jtexpress.com','yl_bigdata@yl-scm.com'],
    email_on_retry=True,
    name='jms_dm__dm_cn_export_departure_store_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_cn_export_departure_store_dt/execute.hql',
    pool_slots=8,
    executor_cores=8,
    executor_memory='10G',
    driver_memory='8G',
    retries=0,
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.maxExecutors': 50,
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',
          'spark.dynamicallocation.enabled': 'true',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,
          'spark.shuffle.service.enabled': 'true',
          'spark.sql.shuffle.partitions': 1000
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_cn_export_departure_store_dt << [jms_ods__tab_barscan_centersend__0730,
                                            jms_ods__tab_barscan_loading__0730,
                                            jms_ods__tab_barscan_unloading__0730,
                                            jms_ods__tab_barscan_difficult__0730,
                                            jms_ods__tab_barscan_collect__0730,
                                            jms_ods__tab_barscan_sign__0730,
                                            jms_ods__tab_aviation_send_record__0730,
                                            jms_ods__tab_send_goods_report__0730,
                                            jms_ods__yl_tmsnew_branch_shipment_stop__0730,
                                            jms_ods__yl_tmsnew_tms_shipment_stop__0730,
                                            jms_ods__yl_tmsnew_branch_shipment__0730,
                                            jms_ods__yl_tmsnew_tms_shipment__0730,
                                            jms_ods__yl_oms_oms_waybill,
                                            jms_ods__yl_oms_interceptorpiece__0730,
                                            jms_dim__dim_lmdm_sys_first_code,
                                            jms_dim__dim_sys_network_detail_dt,
                                            jms_ods__tab_barscan_warehousing,
                                            jms_ods__tab_barscan_taking,
                                            jms_ods__tab_barscan_centerarrival,
                                            jms_ods__tab_barscan_arrival,
                                            jms_ods__tab_reback_transfer_express, ]
